package com.executor.gateway.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 响应式布隆过滤器Redis配置
 * 
 * @author miaoguoxin
 * @date 2024/01/01
 */
@Configuration
public class BloomFilterConfig {

    @Autowired
    private ReactiveRedisConnectionFactory reactiveRedisConnectionFactory;

    /**
     * 配置专门用于布隆过滤器的响应式Redis模板
     */
    @Bean(name = "bloomReactiveRedisTemplate")
    public ReactiveRedisTemplate<String, String> bloomReactiveRedisTemplate() {
        RedisSerializationContext<String, String> serializationContext = RedisSerializationContext
                .<String, String>newSerializationContext()
                .key(new StringRedisSerializer())
                .value(new StringRedisSerializer())
                .hashKey(new StringRedisSerializer())
                .hashValue(new StringRedisSerializer())
                .build();

        ReactiveRedisTemplate<String, String> template = new ReactiveRedisTemplate<>(
                reactiveRedisConnectionFactory, 
                serializationContext
        );
        
        return template;
    }
}